<template>
  <n-modal v-model:show="modelVisbile">
    <div
      class="modal"
      :style="customStyle"
    >
      <div class="modal-title">
        <span>{{ title }}</span>
        <n-icon
          :size="24"
          class="pointer"
          @click="modelVisbile = false"
        >
          <Close />
        </n-icon>
      </div>
      <div
        class="modal-container"
        :style="`height: calc(${height}px - 64px - 57px);`"
      >
        <slot></slot>
      </div>
      <div class="modal-footer">
        <n-flex>
          <slot name="footer"> </slot>
        </n-flex>
      </div>
    </div>
  </n-modal>
</template>

<script lang="ts" setup>
  import { Close } from '@vicons/ionicons5'
  const props = withDefaults(
    defineProps<{
      // 标题
      title?: string
      // 显示
      visible: boolean
      // 宽度
      width?: number
      // 高度
      height?: number
    }>(),
    {
      title: '',
      visible: false,
      width: 500,
      height: 600
    }
  )
  const emits = defineEmits(['update:visible'])

  const modelVisbile = computed({
    get() {
      return props.visible
    },
    set(val) {
      emits('update:visible', val)
    }
  })

  // 自定义样式
  const customStyle = computed(() => {
    return {
      width: `${props.width}px`,
      height: `${props.height}px`
    }
  })
</script>

<style scoped lang="scss">
  .modal {
    border-radius: $radius-default;
    background: #fff;
    &-title {
      font-weight: bold;
      padding: $space-default;
      display: flex;
      align-items: center;
      justify-content: space-between;
      box-sizing: border-box;
      border-bottom: 1px solid #f0f0f0;
    }
    &-container {
      padding: $space-default;
      box-sizing: border-box;
    }
    &-footer {
      height: 64px;
      box-sizing: border-box;
      padding: $space-default;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      border-top: 1px solid $border-color;
    }
  }
</style>
